package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.Country;
import com.tbit.uqbike.client.service.CountryService;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 国家
 *
 * @Author: chen
 * @Description: 国家
 * @Date: 创建于 15:09 2020/2/13
 */
@Controller
@RequestMapping("/country")
public class CountryController {
    @Autowired
    private CountryService countryService;

    /**
     * 查询国家列表
     *
     * @param session  会话
     * @param response 响应
     * @ignoreParams request
     */
    @RequestMapping("/query")
    public void query(HttpSession session, HttpServletRequest request,
                      HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {

            List<Country> list = countryService.query();

            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, list);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }

        OutputUtil.renderText(request, response, map);
    }
}
